package me.winter.imgcmps;

public class RgbPixels {
	
	private int[] rgbPixels;
	private int width, height;
	
	public RgbPixels(int[][] red, int[][] green, int[][] blue) {
		width = red[0].length;
		height = red.length;
		
		rgbPixels = new int[3 * width * height];
		
		flat(red, green, blue);

	}
	
	public RgbPixels(int[] rgbPixels) {
		this.rgbPixels = rgbPixels;
	}
	
	public void setRgbPixels(int[] rgbPixels) {
		this.rgbPixels = rgbPixels;
	}
	
	public int[] getRgbPixelsArray() {
		return rgbPixels;
	}
	
	public int[][] getRedPixelArray() {
		int[][] reds = new int[height][width];
		
		for (int i = 0; i < height; ++i) {
			for (int j = 0; j < width; ++j) {
				reds[i][j] = rgbPixels[i * width + j];
			}
		}
		
		return reds;
	}
	
	public int[][] getGreenPixelArray() {
		int[][] greens = new int[height][width];
		
		for (int i = 0; i < height; ++i) {
			for (int j = 0; j < width; ++j) {
				greens[i][j] = rgbPixels[width * height + i * width + j];
			}
		}
		
		return greens;
	}
	
	public int[][] getBluePixelArray() {
		int[][] blues = new int[height][width];
		
		for (int i = 0; i < height; ++i) {
			for (int j = 0; j < width; ++j) {
				blues[i][j] = rgbPixels[2 * width * height + i * width + j];
			}
		}
		
		return blues;
	}
	
	private void flat(int[][] red, int[][] green, int[][] blue) {
		for (int i = 0; i < height; ++i) {
			for (int j = 0; j < width; ++j) {
				rgbPixels[i * width + j] = red[i][j];
			}
		}
		
		for (int i = 0; i < height; ++i) {
			for (int j = 0; j < width; ++j) {
				rgbPixels[width * height + i * width + j] = green[i][j];
			}
		}
		
		for (int i = 0; i < height; ++i) {
			for (int j = 0; j < width; ++j) {
				rgbPixels[2 * width * height + i * width + j] = blue[i][j];
			}
		}
	}

}
